﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using time;
using time;
using myframework._99_热身.time._2011_10_24_scm;

namespace MvcApplication1.Controllers
{
    public class WorkController : Controller
    {
        //
        // GET: /Work/

        public ActionResult Index()
        {
            return View();
        }


        public ActionResult DataBase(string table = "Clothes")
        {
            DataClasses1DataContext dc = new DataClasses1DataContext();
            ViewData["table"] = table;


            return View(dc.Clothes.Take(100).ToList());
        }

        public ActionResult Clothes(string sortOrder, string searchString)
        {
            DataClasses1DataContext dc = new DataClasses1DataContext();

            var lc=dc.Clothes.Select(s=>s);
            if (!String.IsNullOrEmpty(searchString))
            {
                lc = dc.Clothes.Where(s => s.ProductCode.ToUpper().Contains(searchString.ToUpper())).Take(100);
            }
            else
            {
                lc = dc.Clothes.Take(100);
            }

            switch (sortOrder)
            {
                case "ProductCode":
                    lc = lc.OrderBy(s => s.ProductCode);
                    break;

                case "XPrice":
                    lc = lc.OrderBy(s => s.XPrice);
                    break;

                default:
                    lc = lc.OrderBy(s => s.ProductCode);
                    break;
            }

            

            return View(lc.ToList());
        }

    }
}
